/**
 * @author Steve Cox
 * @date 10/18/2011
 * @description controller utilities for the Implant Patient page of the Thoratec
 * Digital Hub project.
*/
public with sharing class MM_ControllerUtils {
   /**
    * @description given an object field, return the pick list values as a list
    * of SelectOptions that can be displayed by a VF page.
    * @param field - the pick list field
    * @return all pick list options as a list of SelectOptions
   */
   public static List<SelectOption> getPickListAsSelectOptions(
      Schema.SObjectField field) {
      List<SelectOption> options = new List<SelectOption>();
      if (null != field) {
         Schema.PicklistEntry [] values = field.getDescribe().getPickListValues();
         for (Schema.PicklistEntry val : values) {
            options.add(new SelectOption(val.getValue(), 
               val.getLabel()));
         }
      }
      
      return options;
   }
}

/**
 * @author Steve Cox
 * @date 10/18/2011
 * @description controller utilities tests for the Implant Patient page of the 
 * Thoratec Digital Hub project.
*/
@isTest
public with sharing class MM_ControllerUtilsTests {
   static testMethod void testGetPickListAsSelectedOptions() {
      List<SelectOption> results = null;

      // null field
      results = MM_ControllerUtils.getPickListAsSelectOptions(null);
      System.assert(results.IsEmpty());

      // non-picklist field
      results = MM_ControllerUtils.getPickListAsSelectOptions(Account.Id);
      System.assert(results.IsEmpty());

      // picklist field
      results = MM_ControllerUtils.getPickListAsSelectOptions(Account.Type);
      System.assert(!results.IsEmpty());
   }
}
